*********************************
*** Data PREPERATION Trump paper
*** Created: 31/10/2020
*** Last updated: 21/05/2021
clear all
set scheme plottig
 

	local user = 1		/* user 1 = sergi, user 2 = Anja */

	if `user' == 1 {			// input relevant file path as per your computer

		global		main "/Users/aneundorf/Dropbox/Project_Populism/BA project/Analysis/Trump_Replication files/"
		global 		graphs 			"${main}Graphs/"
		global 		results			"${main}Results/"
	}

cd "${main}"

*** Import and save data

import spss using "Data/Deltapoll-Glasgow201030.sav"
save "Data/Deltapoll-Glasgow201030.dta", replace

***--------------------------------------------
***Recoding variables

* Treatment 
tab Group
recode Group (2=3) (3=2)
lab def treatlbl 1 "T1 - Economy" 3"T3 - Chinese virus" 2"T2 - Gov. managment" 4"Control"
lab val Group treatlbl

tab Group, gen(group)

** Mediation variables
 gen econ_all=.
replace econ_all=1 if Group==1
replace econ_all=0 if Group==2
replace econ_all=0 if Group==3
replace econ_all=0 if Group==4

gen econ_control=.
replace econ_control=1 if Group==1
replace econ_control=0 if Group==4

gen manage_all=.
replace manage_all=0 if Group==1
replace manage_all=0 if Group==2
replace manage_all=1 if Group==3
replace manage_all=0 if Group==4

gen manage_control=.
replace manage_control=1 if Group==2
replace manage_control=0 if Group==4

* Therometer questions
recode Q2_1 999=., gen (trump_feeling)
recode Q2_2 999=., gen (biden_feeling)

corr trump_feeling biden_feeling
sum trump_feeling biden_feeling,d

* Vote question 

tab1 Q3a
gen trump_vsbiden=.
replace trump_vsbiden=1 if Q3a==1
replace trump_vsbiden=0 if Q3a==2
tab trump_vsbiden
lab var trump_vsbiden "Vote: Trump vs Biden"
bys qSTATE: sum trump_vsbiden

recode Q3a (1=1) (2/5=0), gen(voteTrump)
lab var voteTrump "Vote: Trump vs all else"

tab Q3a voteTrump

* Unemployment risk
gen unemp_prob=.
replace unemp_prob=Q9a if Group==2 | Group ==3 | Group==4
replace unemp_prob=Q1a if Group==1
replace unemp_prob=. if unemp_prob >=5

recode unemp_prob (1=4)(2=3)(3=2)(4=1)
lab def unemplbl 1"Very likley" 4"Not likely at all"
lab val unemp_prob unemplbl

tab unemp_prob Q1a

* Immigration preferences 
gen immig_pref=.
replace immig_pref=Q9b if Group==1 | Group ==2 | Group==4
replace immig_pref=Q1b if Group==3
replace immig_pref=. if immig_pref >=6

sum immig_pref, d
gen immig01=(immig_pref-r(min))/(r(max)-r(min))
lab var immig01 "Anti-immigration pref."

* Government handling 
tab1 Q1c Q9c
gen gov_handle=.
replace gov_handle=Q9c if Group==3 | Group ==1 | Group==4
replace gov_handle=Q1c if Group==2
replace gov_handle=. if gov_handle >=6
tab gov_handle

** Populist preferences
recode Q4 1=5 2=4 3=3 4=2 5=1 else=., gen(populism) /*from less to more populist attitudes*/
sum populism, d
gen populism01 = (populism-r(min))/(r(max)-r(min))
lab var populism01 "Populism"

** Unemployment spending preferences
recode Q5 11/.=., gen(spending_unemp) /*from left to right-wing preferences*/
sum spending_unemp, d
gen spending01=(spending_unemp-r(min))/(r(max)-r(min))
 lab var spending_unemp "Anti-tax pref."
 lab var spending01 "Anti-tax pref."

* Income
tab QDP5
numlabel labels20, add
recode QDP5 98/.=.
gen income_linear=QDP5
xtile income_cat=income_linear, nq(3)
sum income_linear,d
gen income_binary=.
replace income_binary=1 if income_linear>8
replace income_binary=0 if income_linear<=8

* Partisanship
recode QDP4 8/.=. /*partisanship variable*/
recode QDP4 1/2=0 6/7=0 3/5=1, gen(independent)
recode QDP4 1/2=1 6/7=3 3/5=2, gen(partisan_cat)
tab QDP4 partisan_cat
lab def partlbl 1"Democrat" 2"Independent" 3"Republican"
lab val partisan_cat partlbl

* Gender
tab QDP1
tab QDP1, nolabel
recode QDP1 (1=0)(2=1) (3=0), gen(female)
tab female // 51.3% women
lab def gndlbl 1"Women" 0"Men"
lab val female gndlbl
lab var female "Women"
tab female

* Age
tab QDP2
sum QDP2,d // Average age  48.5

gen age = QDP2
recode age (18/54=0) (55/99=1), gen(age55)
lab var age "Age"
lab def agelbl 0"Below 55" 1"55+"
lab val age55 agelbl

sum age, d
gen age01=(age-r(min))/(r(max)-r(min))
lab var age01 "Age"

* Education
tab QDP3
codebook QDP3, all

recode QDP3 (1/3=3 "No High School") (4/6=2 "High School") (7/11=1 "Degree") (99=.), gen(educ_cat)
tab  QDP3 educ_cat
tab educ_cat, gen(educ)

* Domicile
tab QDP6
tab QDP6, nolabel

recode QDP6 (1=4 "Urban") (2=3 "Suburban") (3=2 "City or sizable town") (4/5=1 "Rural") (98/99=.), gen(domicile)

tab domicile, gen(dom) 

* Ethnicity 
// we did not have enough Asians and no Middle Eastern
tab QDP7
tab QDP7, nolabel
recode QDP7 (1=1 "White") (3=2 "Black") (2=3 "Hispanic") (4/16=4 "Other") (99=.), gen(ethnic)

tab  QDP7 ethnic
tab ethnic, gen(ethnic)

* Religion
tab QDP8
tab  QDP8, nolabel
gen religion = QDP8
lab def relilbl 1"Religious + attend at least monthly" 2"Religious + little attend." 3 "Not religious"
lab val religion relilbl
tab religion, gen(relig)

* Born
tab QDP9
drop if QDP9 !=1 /*only US born*/


***** Save data
save "Data/US_data_recoded.dta", replace
